<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>管理端活动</title>
  <link rel="stylesheet" href="../layui/css/layui.css">
  <script src="../layui/layui.js"></script>
  <script type="text/javascript" src="../js/basic.js"></script>
  <link rel="stylesheet" href="../css/basic.css">
  <style>
    .btn-wrap{
      margin:5px 20px;
    }
    .btn-wrap>button{
      float: right;
      margin: 0 10px;
    }  
  </style>
</head>
<body>
  <div class="layui-col-sm8 layui-col-sm-offset2">
    <div class="btn-wrap layui-clear">
        <div class="layui-col-sm4 layui-form-item">
            <label class="layui-form-label">活动名：</label>
            <div class="layui-input-block">
            <input type="text" name="userName" class="layui-input">
            </div>
        </div>
        <div class="layui-col-sm4">
            <label class="layui-form-label">活动时间：</label>
            <div class="layui-input-block">
            <input type="text" name="userAccount" class="layui-input">
            </div>
        </div>
        <div class="layui-col-sm2">
            <a id="searchIpt" class="layui-btn layui-btn-normal">搜索</a>
        </div>
      <button id="addCounter" class="add-counter layui-btn layui-btn-normal">发布活动</button>
    </div>
    <table id="table" lay-filter="table"></table>
  </div>
</body>
<!--发布活动信息-->
<form id="addActivity" class="layui-form bs-hidden fm-in" lay-filter="addActivity">
  <div class="layui-form-item">
      <label class="layui-form-label">活动代号：</label>
      <div class="layui-input-block">
          <input type="text" name="act_no" class="layui-input">
      </div>
  </div>
 <!--  
  <div class="layui-form-item">
      <label class="layui-form-label">活动名称：</label>
      <div class="layui-input-block">
      <input type="text" name="a2" readonly  lay-verify="required" placeholder="触角动漫社明伦校区宅舞演出" autocomplete="off" class="layui-input">
      </div>
  </div>
 -->
  <div class="layui-form-item">
      <label class="layui-form-label">活动名称：</label>
      <div class="layui-input-block">
          <input type="text" name="act_name" required  lay-verify="required" placeholder="请输入活动名称" autocomplete="off" class="layui-input">
      </div>
  </div>
  <div class="layui-form-item">
      <label class="layui-form-label">活动地点：</label>
      <div class="layui-input-block">
          <input type="text" name="act_loc" required  lay-verify="required" placeholder="请输入活动地点" autocomplete="off" class="layui-input">
      </div>
  </div>
  <div class="layui-form-item">
      <label class="layui-form-label">开始时间：</label>
      <div class="layui-input-block">
        <input type="text" name="act_start" id="act_start" lay-filter="act_start" class="layui-input">
      </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">截止时间：</label>
    <div class="layui-input-block">
      <input type="text" name="act_end" id="act_end" lay-filter="act_end" class="layui-input">
    </div>
</div>
  <div class="layui-form-item">
      <label class="layui-form-label">活动介绍：</label>
      <div class="layui-input-block">
        <textarea name="act_intro" placeholder="请输入内容" class="layui-textarea"></textarea>
      </div>
  </div>
  <div class="layui-form-item">
      <div class="layui-input-block btn-center">
          <button class="layui-btn" lay-submit lay-filter="addPwd">提交</button>
          <button type="reset" class="layui-btn layui-btn-primary">重置</button>
      </div>
  </div>
</form>

<!-- 修改社团信息 -->
<form id="updateActivity" class="layui-form bs-hidden fm-in" lay-filter="updateActivity">
  <div class="layui-form-item">
      <label class="layui-form-label">活动代号：</label>
      <div class="layui-input-block">
          <input type="text" name="act_noD" id="act_noD" class="layui-input" readonly required  lay-verify="required" autocomplete="off" >
      </div>
  </div>
<!--  
  <div class="layui-form-item bs-hidden">
      <label class="layui-form-label">活动举办社团编号：</label>
      <div class="layui-input-block">
      <input type="text" name="soc_noD" id="soc_noD" required  lay-verify="required" placeholder="请输入活动举办社团" autocomplete="off" class="layui-input">
      </div>
  </div>
-->  
  <div class="layui-form-item">
      <label class="layui-form-label">活动名称：</label>
      <div class="layui-input-block">
          <input type="text" name="act_nameD" id="act_nameD" required  lay-verify="required" placeholder="请输入活动名称" autocomplete="off" class="layui-input">
      </div>
  </div>
  <div class="layui-form-item">
      <label class="layui-form-label">活动地点：</label>
      <div class="layui-input-block">
          <input type="text" name="act_locD" id="act_locD" required  lay-verify="required" placeholder="请输入活动地点" autocomplete="off" class="layui-input">
      </div>
  </div>
  <div class="layui-form-item">
      <label class="layui-form-label">开始时间：</label>
      <div class="layui-input-block">
        <input type="text" name="act_startD" id="act_startD" lay-filter="act_start" class="layui-input">
      </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">截止时间：</label>
    <div class="layui-input-block">
      <input type="text" name="act_endD" id="act_endD" lay-filter="act_end" class="layui-input">
    </div>
</div>
  <div class="layui-form-item">
      <label class="layui-form-label">活动介绍：</label>
      <div class="layui-input-block">
        <textarea name="act_introD" id="act_introD"  placeholder="请输入内容" class="layui-textarea"></textarea>
      </div>
  </div>
  <div class="layui-form-item">
      <div class="layui-input-block btn-center">
          <button class="layui-btn" lay-submit lay-filter="updatePwd">提交</button>
          <button type="reset" class="layui-btn layui-btn-primary">重置</button>
      </div>
  </div>
</form>
<span class="bs-hidden" id="Sid"></span>
<!-- 表格里的操作按钮 -->
<script type="text/html" id="ipts">
  <a lay-event="edit" class="layui-btn layui-btn-xs">编辑</a>
  <a lay-event="del" class="layui-btn layui-btn-xs">删除</a>
</script>
<script>
layui.use(['laydate','table', 'layer', 'jquery','form'], function () {
  var laydate = layui.laydate;
  var table = layui.table
  var layer = layui.layer
  var $ = layui.jquery
  var form = layui.form;
  var mydate = new Date()
  var dataNow = mydate.toLocaleDateString()
//第一个实例
$.ajax({
  	type:"POST",
  	url:"/user/getManUser",
  	dataType:"json",
  	error:function(){
  		console.log("error!");
  	},
  	success:function(data){
  		console.log(data);
  		$('#Sid').html(data.soc_no);
  	//	alert($('#Sid').text());
  		searchAll();
  	}
  })


function searchAll(){
	$.ajax({
		type:"GET",
		url:"/manager/serchMyActivity",
		data:{"soc_no":$('#Sid').text()},//写完登录后更改
		dataType:"json",
		error:function(){
			alert("error!");
		},
		success:function(data){
			console.log(data);
			//注入动态表格
			showTable(data);
			//注入修改对话框
			//$('#act_noD').val(data[0].act_no);
			//$('#soc_noD').val(data[0].soc_no);
			//$('#act_nameD').val(data[0].act_name);
			//$('#act_locD').val(data[0].act_loc);
			//$('#act_startD').val(dateFormat(data[0].act_start));
			//$('#act_endD').val(dateFormat(data[0].act_end));
			//$('#act_introD').val(data[0].act_intro);		
		}
	})  	  
}
//searchAll();
function showTable(tableData){
  table.render({
    id: 'tableImp',
    elem: '#table',
    page: true,//开启分页
    cols: [
        [//表头
          {
            field: 'act_no',
            title: '活动号',
            width: '10%',
            sort: true,
            fixed: 'left',
            align: 'center'
          }, {
            field: 'act_name',
            title: '活动名称',
            width: '10%',
            align: 'center'
          }, {
            field: 'act_loc',
            title: '活动地点',
            width: '13%',
            align: 'center'
          },  {
            field: 'act_start',
            title: '开始时间',
            width: '13%',
            align: 'center',
            templet: '#StartTime'
          },{
            field: 'act_end',
            title: '截止时间',
            width: '13%',
            align: 'center',
            templet: '#EndTime'
          },{
            field: 'act_intro',
            title: '活动介绍',
            width: '28%',
            align: 'center'
          },{
            fixed: 'right',
            title: '操作',
            align: 'center',
            width: '13%',
            toolbar: '#ipts'
          }
        ]
      ]
      //加载数据
      ,data:tableData
      
  });
}
  table.on('tool(table)',function (obj) {  
    var event = obj.event
    if(event === 'edit') {
      layer.open({
        type: 1,
        closeBtn: 1,
        title: '修改社员信息',
        content: $('#updateActivity'),
        area: ['800px', '600px'],
        offset: '10px',
        success: function(layero, index){
            console.log(layero, index);
			$('#act_noD').val(obj.data.act_no);
			$('#soc_noD').val(obj.data.soc_no);
			$('#act_nameD').val(obj.data.act_name);
			$('#act_locD').val(obj.data.act_loc);
			$('#act_startD').val(dateFormat(obj.data.act_start));
			$('#act_endD').val(dateFormat(obj.data.act_end));
			$('#act_introD').val(obj.data.act_intro);	
            
          }
      })
    }
    //删除
    else if(event === 'del') {
        layer.open({
          type:1,
          closeBtn: 0,
          title:"提示信息",
          content:"<span style='font-size:20px; margin-left:40px'>"+"真的要删除么？"+"</span>",
          area:['200px','150px'],
          offset: '10px',
          btn:['确定','取消'],
          btnAlign:'c',
          yes:function(index, layero){
        	  $.ajax({
          		type:"POST",
          		data:{
          			act_no:obj.data.act_no
          		},
          		url:"/manager/deleteActivity",
          		dataType:"json",
          		error:function(){
          			alert("error!");
          		},
          		success:function(data){
          			if(data == true){
          				layer.msg('删除成功!',{
          					time:1000
          				},function(){
          					layer.closeAll();
          				});
          				searchAll();
          				return false;
          			}else if(data == false){
          				layer.msg('删除失败!',{
          					time:1000
          				},function(){
          					layer.closeAll();
          				});
          				searchAll();
          				return false;
          			}
          		}	
          	})
          },
          btn2:function(index, layero){
              layer.close(index);
              return false;
          }
        })
    }
  })
  //新增
  $('#addCounter').click(function () {
    layer.open({
          title:'发布活动详情',
          type:1,
          content:$('#addActivity'),
          area:['800px','600px'],
          offset: '10px',
      });
  });
  //监听发布活动提交
  form.on('submit(addPwd)', function(data){
	  console.log(data.field);
	    $.ajax({
	    	type:"GET",
	    	url:"/manager/saveActivity",
	    	data:{
	    		act_name:data.field.act_name,
	    		act_loc:data.field.act_loc,
	    		act_start:data.field.act_start,
	    		act_end:data.field.act_end,
	    		act_intro:data.field.act_intro,
	    		act_no:data.field.act_no,
	    		act_public:"1",
	    		soc_no:$('#Sid').text()
	    	},
	    	error:function(){
	    		alert("error!");
	    	},
	    	success:function(data){
	    		console.log(data);
	    		if(data == true){
	    			layer.msg('发布成功!',{
	    				time:1000
	    			},function(){
	    				layer.closeAll();
	    			});
	    			searchAll();
	    			return false;
	    		}else if(data == false){
	    			layer.msg('发布失败!',{
	    				time:1000
	    			},function(){
	    				layer.closeAll();
	    			});
	    			searchAll();
	    			return false;
	    		}
	    	}	
	    })   
    return false;
  });
  //监听修改活动提交
 form.on('submit(updatePwd)', function(data){
	console.log(data.field);
    $.ajax({
    	type:"GET",
    	url:"/manager/changeActivityMessage",
    	data:{
    		act_name:data.field.act_nameD,
    		act_loc:data.field.act_locD,
    		act_start:data.field.act_startD,
    		act_end:data.field.act_endD,
    		act_intro:data.field.act_introD,
    		act_no:data.field.act_noD,
    		act_public:"1",
    		soc_no:$('#Sid').text()
    	},
    	error:function(){
    		alert("error!");
    	},
    	success:function(data){
    		console.log(data);
    		if(data == true){
    			layer.msg('修改成功!',{
    				time:1000
    			},function(){
    				layer.closeAll();
    			});
    			searchAll();
    			return false;
    		}else if(data == false){
    			layer.msg('修改失败!',{
    				time:1000
    			},function(){
    				layer.closeAll();
    			});
    			searchAll();
    			return false;
    		}
    	}	
    }) 
    return false;
  }); 
  
  
//执行一个laydate实例
laydate.render({
  elem: '#act_start' //指定元素
  ,format:"yyyy-MM-dd"
});
laydate.render({
	 elem: '#act_end' //指定元素
	,format:"yyyy-MM-dd"
});


})
</script>

<script type="text/html" id="StartTime">  
  		{{dateFormat(d.act_start) }}
</script>
<script type="text/html" id="EndTime">  
		{{dateFormat(d.act_end) }}
</script>
</html>

